﻿@using Coslen.Framework.Helpers
@using Coslen.Framework
@using MvcPaging
@model Coslen.TahorCRM.Domain.Entities.ViewModels.Searching.ContactSearchViewModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>
    Contacts</h2>
<div>
    @using (Html.BeginForm("Index", "Contact", new { page = 0 }, FormMethod.Post, new { id = "myform" }))
    {
        <div class="filterHeader">
            Search</div>
        <div class="filter">
            <fieldset>
                <div class="editor-row">
                    <div class="editor-label">
                        @Html.LabelFor(model => model.FirstName)
                    </div>
                    <div class="editor-field">
                        @Html.EditorFor(model => model.FirstName)
                    </div>
                </div>
                <div class="editor-row">
                    <div class="editor-label">
                        @Html.LabelFor(model => model.LastName)
                    </div>
                    <div class="editor-field">
                        @Html.EditorFor(model => model.LastName)
                    </div>
                </div>
                <div class="editor-row">
                    <div class="editor-label">
                    </div>
                    <div class="editor-field">
                        <input name="SearchButton" type="submit" value="Search" />
                    </div>
                </div>
            </fieldset>
        </div>
        
        <div class="grid-header">
            <div class="grid-results">
                <div class="inner">
                    <span style="float: left">
                        @string.Format("{0} records found. Page {1} of {2}", Model.SearchResults.TotalItemCount, Model.SearchResults.PageNumber, Model.SearchResults.PageCount)
                    </span><span style="float: right">Show @Html.DropDownList("PageSize", Model.PageSizeList, new { onchange = "document.getElementById('myform').submit()" })
                        results per page </span>
                    <div style="clear: both">
                    </div>
                </div>
            </div>
            <div class="paging">
                <div class="pager">
                    @Html.Pager(Model.SearchResults.PageSize, Model.SearchResults.PageNumber, Model.SearchResults.TotalItemCount, new { FirstName = Model.FirstName, LastName = Model.LastName, PageSize = Model.PageSize })
                </div>
            </div>
        </div>
    }
</div>
@if (User.IsInRole("CanEditContact"))
{
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
}
<table class="GenericTable fullWidth">
    <tr class="GenericTable-HeaderRow">
        <th>
            First Name
        </th>
        <th>
            Last Name
        </th>
        <th>
            Middle Names
        </th>
        <th>
            Title
        </th>
        <th>
            Born On
        </th>
        <th>
            Gender
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model.SearchResults.Select((x, i) => new { Data = x, Index = i }))
    {
        <tr class="@( item.Index % 2 == 0 ? "GenericTable-RowAlt" : "GenericTable-Row")">
            <td>
                @Html.DisplayFor(modelItem => item.Data.FirstName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.LastName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.MiddleNames)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.Title.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.BornOn)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Data.Gender.Name)
            </td>
            <td>
                @Html.ImageActionLink(
               Url.Content("~/Content/Images/edit.png"),
               "View",
               "Details",
               "Contact",
            new { area = "Contacts", id = item.Data.ContactId, source = "Contact:Index:" + item.Data.ContactId },
               new { @class = "" },
               new { @class = "actionIcon" })
            </td>
        </tr>
    }
</table>
<div class="grid-header">
    <div class="paging">
        <div class="pager">
            @Html.Pager(Model.SearchResults.PageSize, Model.SearchResults.PageNumber, Model.SearchResults.TotalItemCount, new { PageSize = Model.PageSize, FirstName = Model.FirstName, LastName = Model.LastName })
        </div>
    </div>
</div>